package com.example.leetdemo.finash;

public class Solution01_05 {

    public static boolean oneEditAway(String first, String second) {
        if (Math.abs(first.length() - second.length()) > 1) {
            return false;
        }
//        int
        for (int i = 0; i < Math.min(first.length(), second.length()); i++) {
            if (first.charAt(i) != second.charAt(i)) {
                if (first.length() == second.length()) {
                    if (i == first.length() - 1) {
                        return true;
                    } else {
                        return first.substring(i + 1).equals(second.substring(i + 1));
                    }
                }
                if (first.length() > second.length()) {
                    return first.substring(i + 1).equals(second.substring(i));
                }
                if (first.length() < second.length()) {
                    return first.substring(i).equals(second.substring(i + 1));
                }
            }

        }
        return true;
    }

    public static void main(String[] args) {
        String a = "11";
        System.err.println(oneEditAway("123", "1234"));
    }

}
